package com.bc.bcbuyerapihttp.controller;

import com.bc.bcapi.service.LanguageService;
import com.bc.bcapi.service.T_Common_reportService;
import com.bc.bcapi.service.T_Common_report_subService;
import com.bc.bcapi.service.T_Common_report_typeService;
import com.bc.bcbuyerapihttp.common.UserContext;
import com.bc.bcmodel.BuyerUserInfo;
import com.bc.bcmodel.consts.GlobalSettings;
import com.bc.bcmodel.domain.T_Common_reportModel;
import com.bc.bcmodel.domain.T_Common_report_subModel;
import com.bc.bcmodel.req.CommonReportDetailReq;
import com.bc.bcmodel.req.ProjectSearchParamReq;
import com.bc.bcmodel.req.ReportSearchParamReq;
import com.bc.bcmodel.resp.T_Common_reportModelResp;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Name ReportController
 * @Description TODO
 * @Author douhaichao
 * @Date 2019/4/18 10:05
 * @Version 1.0
 **/
@RestController
@Api(value = "举报")
@RequestMapping("report")
public class ReportController {

    @Autowired
    T_Common_reportService t_common_reportService;
    @Autowired
    T_Common_report_typeService t_common_report_typeService;
    @Autowired
    LanguageService languageService;
    @Autowired
    T_Common_report_subService t_common_report_subService;

    @ApiOperation("获取举报类型")
    @RequestMapping(value = "gettype", method = RequestMethod.GET)
    public JsonResult getReportType(HttpServletRequest request, HttpServletResponse response) {
        String language = languageService.getCurrentLanguage(request, response, GlobalSettings.LANGUAGE);
        return t_common_report_typeService.getReportType(language);
    }

    @ApiOperation("添加举报")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public JsonResult add(@RequestBody T_Common_reportModel req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        req.setAudit_status(0);
        t_common_reportService.insertReport(req);
        return new JsonResult(HttpReturnRnums.Success);
    }

    @ApiOperation("查询举报")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public JsonResult list(@RequestBody T_Common_reportModel req,
                           HttpServletRequest request, HttpServletResponse response) {
        req.setAudit_status(1);
        PageInfo<T_Common_reportModelResp> pageInfo = t_common_reportService.getReportList(req);
        return new JsonResult(pageInfo);
    }
    @ApiOperation("查询举报详情")
    @RequestMapping(value = "detail", method = RequestMethod.POST)
    public JsonResult list(@RequestBody CommonReportDetailReq req,
                           HttpServletRequest request, HttpServletResponse response) {
        PageInfo<T_Common_report_subModel> resp = t_common_reportService.getReportDetail(req);
        return new JsonResult(resp);
    }
}
